<p>To configure Spring Boot to use the H2 database and enable the H2
console page, follow these steps:</p>
<ol type="1">
<li><p><strong>Add H2 Dependency</strong>:</p>
<p>Open your <code>pom.xml</code> file and make sure you have the H2
database dependency added. It should look something like this:</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode xml"><code class="sourceCode xml"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>&lt;<span class="kw">dependency</span>&gt;</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>    &lt;<span class="kw">groupId</span>&gt;com.h2database&lt;/<span class="kw">groupId</span>&gt;</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>    &lt;<span class="kw">artifactId</span>&gt;h2&lt;/<span class="kw">artifactId</span>&gt;</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>    &lt;<span class="kw">scope</span>&gt;runtime&lt;/<span class="kw">scope</span>&gt;</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>&lt;/<span class="kw">dependency</span>&gt;</span></code></pre></div></li>
<li><p><strong>Configure H2 Database</strong>:</p>
<p>Open your <code>application.properties</code> or
<code>application.yml</code> file and add the following
configurations:</p>
<p>For <code>application.properties</code>:</p>
<pre class="properties"><code>spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.h2.console.enabled=true</code></pre>
<p>For <code>application.yml</code>:</p>
<div class="sourceCode" id="cb3"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">spring</span><span class="kw">:</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="at">  </span><span class="fu">datasource</span><span class="kw">:</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="at">    </span><span class="fu">url</span><span class="kw">:</span><span class="at"> jdbc:h2:mem:testdb</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="at">    </span><span class="fu">driver-class-name</span><span class="kw">:</span><span class="at"> org.h2.Driver</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="at">    </span><span class="fu">username</span><span class="kw">:</span><span class="at"> sa</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="at">    </span><span class="fu">password</span><span class="kw">:</span><span class="at"> password</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="at">  </span><span class="fu">h2</span><span class="kw">:</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="at">    </span><span class="fu">console</span><span class="kw">:</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="at">      </span><span class="fu">enabled</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span></code></pre></div>
<p>This configuration sets up an H2 in-memory database named
<code>testdb</code> with default username <code>sa</code> and password
<code>password</code>.</p></li>
<li><p><strong>Access H2 Console</strong>:</p>
<p>Start your Spring Boot application. Once it’s up and running, open a
web browser and go to <code>http://localhost:8080/h2-console</code>.</p>
<p>You will be presented with an H2 login page. Use the same credentials
specified in the <code>application.properties</code> or
<code>application.yml</code> file (<code>username: sa</code>,
<code>password: password</code>), and connect to the database.</p>
<p>Make sure that the JDBC URL matches the one specified in the
configuration.</p></li>
<li><p><strong>Verify Connection</strong>:</p>
<p>You should now be able to access the H2 console and interact with the
database.</p></li>
</ol>
<p>Remember, the H2 database is an in-memory database, which means that
the data is lost when the application is stopped. For a persistent
database, you would need to configure a different database like MySQL,
PostgreSQL, etc.</p>
